package com.tianqu.tms.core.mail;

import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

import javax.mail.internet.InternetAddress;

/**
 * mail所需的bean对象
 * @author liugang
 *
 */
public class MailBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * <p>发信者(From)。</p>
	 */
	private InternetAddress from = null;

	/**
	 * <p>发信者(Envelope From)。</p>
	 */
	private InternetAddress envelopeFrom = null;

	/**
	 * <p>发信者的地址(To)。</p>
	 */
	private InternetAddress[] to = null;

	/**
	 * <p>发信者的地址(Envelope To)。</p>
	 */
	private InternetAddress[] envelopeTo = null;

	/**
	 * <p>发信者的地址(CC)。</p>
	 */
	private InternetAddress[] cc = null;

	/**
	 * <p>发信者的地址(BCC)。</p>
	 */
	private InternetAddress[] bcc = null;

	/**
	 * <p>回信地址(Reply-to)。</p>
	 */
	private InternetAddress[] replyTo = null;

	/**
	 * <p>题目(Subject)。</p>
	 */
	private String subject = null;

	/**
	 * <p>内容(Text)。</p>
	 */
	private String text = null;

	/**
	 * <p>附件(Attachment File)。</p>
	 */
	private File[] attachmentFile = null;

	/**
	 * <p>附件(Attachment Text)。</p>
	 */
	private AttachmentTextBean[] attachmentText = null;

	/**
	 * <p>附件(Attachment Bytes)。</p>
	 */
	private ByteArrayDataSource[] attachmentBytes = null;

	/**
	 * <p>MailBean的instance</p>
	 */
	public MailBean() {
		super();
	}

	/**
	 * <p>邮件所有内容的获取</p><br />
	 * 主要是为了debug时候使用
	 * 
	 * @return String 
	 */
	public String toString() {

		return
		"发信者(From)："                   + this.from            + ", " +
		"发信者(Envelope From)："          + this.envelopeFrom    + ", " +
		"发信者的地址(To)："                     + getToAsList()        + ", " +
		"发信者的地址(Envelope To)："            + getEnvelopeToAsList() + ", " +
		"发信者的地址(CC)："                     + getCcAsList()              + ", " +
		"发信者的地址(BCC)："      + getBccAsList()             + ", " +
		"回信地址(Reply-to)："     + getReplyToAsList()         + ", " +
		"附件(Attachment File)："  + getAttachmentFileAsList()  + ", " +
		"附件(Attachment Text)："  + getAttachmentTextAsList()  + ", " +
		"附件(Attachment Bytes)：" + getAttachmentBytesAsList() + ", " +
		"题目(Subject)："                  + this.subject         + ", " +
		"内容(Text)："                    + this.text
		;
	}

	/**
	 * <p>读取对象</p><br />
	 * 
	 * @param input 读取的对象
	 * @throws IOException 对象读取失败场合
	 * @throws ClassNotFoundException 对象类没有找到场合
	 */
	private void readObject(ObjectInputStream input) throws IOException,ClassNotFoundException {
		input.defaultReadObject();
	}

	/**
	 * <p>获得附件(Attachment Bytes)</p>
	 * 
	 * @return 返回附件(Attachment Bytes)包含的列表(数组)
	 */
	public ByteArrayDataSource[] getAttachmentBytes() {
		return attachmentBytes;
	}

	/**
	 * <p>获得附件(Attachment Bytes)</p>
	 * 
	 * @return 返回附件(Attachment Bytes)包含的列表(list)
	 */
	public List getAttachmentBytesAsList() {
		if ( attachmentBytes == null ) {
			return null;
		}
		return Arrays.asList( attachmentBytes );
	}

	/**
	 * <p>获得附件(Attachment File)</p>
	 * 
	 * @return 返回附件(Attachment Bytes)包含的列表(数组)
	 */
	public File[] getAttachmentFile() {
		return attachmentFile;
	}

	/**
	 * <p>获得附件(Attachment File)</p>
	 * 
	 * @return 返回附件(Attachment Bytes)包含的列表(list)
	 */
	public List getAttachmentFileAsList() {
		if ( attachmentFile == null ) {
			return null;
		}
		return Arrays.asList( attachmentFile );
	}

	/**
	 * <p>获得附件(Attachment Text)</p>
	 * 
	 * @return 返回附件(Attachment Text)包含的列表(数组)
	 */
	public AttachmentTextBean[] getAttachmentText() {
		return attachmentText;
	}

	/**
	 * <p>获得附件(Attachment Text)</p>
	 * 
	 * @return 返回附件(Attachment Text)包含的列表(list)
	 */
	public List getAttachmentTextAsList() {
		if ( attachmentText == null ) {
			return null;
		}
		return Arrays.asList( attachmentText );
	}

	/**
	 * <p>获得发信者的地址(BCC)</p>
	 * 
	 * @return 返回发信者的地址(BCC)的列表（数组）
	 */
	public InternetAddress[] getBcc() {
		return bcc;
	}

	/**
	 * <p>获得发信者的地址(BCC)</p>
	 * 
	 * @return 返回发信者的地址(BCC)的列表（list）
	 */
	public List getBccAsList() {
		if ( bcc == null ) {
			return null;
		}
		return Arrays.asList( bcc );
	}

	/**
	 * <p>获得发信者的地址(CC)。</p>
	 * 
	 * @return 返回发信者的地址(CC)的列表（数组）
	 */
	public InternetAddress[] getCc() {
		return cc;
	}

	/**
	 * <p>获得发信者的地址(CC)。</p>
	 * 
	 * @return 返回发信者的地址(CC)的列表（list）
	 */
	public List getCcAsList() {
		if ( cc == null ) {
			return null;
		}
		return Arrays.asList( cc );
	}

	/**
	 * <p>获得发信者(Envelope From)</p>
	 * 
	 * @return 返回发信者(Envelope From)的地址
	 */
	public InternetAddress getEnvelopeFrom() {
		return envelopeFrom;
	}

	/**
	 * <p>获得发信者的地址(Envelope To)</p>
	 * 
	 * @return 返回发信者的地址(Envelope To)的列表（数组）
	 */
	public InternetAddress[] getEnvelopeTo() {
		return envelopeTo;
	}

	/**
	 * <p>获得发信者的地址(Envelope To)</p>
	 * 
	 * @return 返回发信者的地址(Envelope To)的列表（list）
	 */
	public List getEnvelopeToAsList() {
		if ( envelopeTo == null ) {
			return null;
		}
		return Arrays.asList( envelopeTo );
	}

	/**
	 * <p>获得发信者(From)</p>
	 * 
	 * @return 返回发信者(From)的地址
	 */
	public InternetAddress getFrom() {
		return from;
	}

	/**
	 * <p>获得回信地址(Reply-to)。</p>
	 * 
	 * @return 获得回信地址(Reply-to)的列表（数组）
	 */
	public InternetAddress[] getReplyTo() {
		return replyTo;
	}

	/**
	 * <p>获得回信地址(Reply-to)。</p>
	 * 
	 * @return 获得回信地址(Reply-to)的列表（list）
	 */
	public List getReplyToAsList() {
		if ( replyTo == null ) {
			return null;
		}
		return Arrays.asList( replyTo );
	}

	/**
	 * <p>获得题目(Subject)</p>
	 * 
	 * @return String 题目(Subject)
	 */
	public String getSubject() {
		return subject;
	}

	/**
	 * Returns the text.
	 * @return String
	 */
	public String getText() {
		return text;
	}

	/**
	 * <p>获得发信者的地址(TO)。</p>
	 * 
	 * @return 取得发信者的地址(TO)的列表（数组）
	 */
	public InternetAddress[] getTo() {
		return to;
	}

	/**
	 * <p>获得发信者的地址(TO)。</p>
	 * 
	 * @return 取得发信者的地址(TO)的列表（list）
	 */
	public List getToAsList() {
		if ( to == null ) {
			return null;
		}
		return Arrays.asList( to );
	}

	public void setAttachmentBytes(ByteArrayDataSource[] attachmentBytes) {
		this.attachmentBytes = attachmentBytes;
	}

	public void setAttachmentFile(File[] attachmentFile) {
		this.attachmentFile = attachmentFile;
	}

	public void setAttachmentText(AttachmentTextBean[] attachmentText) {
		this.attachmentText = attachmentText;
	}

	public void setBcc(InternetAddress[] bcc) {
		this.bcc = bcc;
	}

	public void setCc(InternetAddress[] cc) {
		this.cc = cc;
	}

	public void setEnvelopeFrom(InternetAddress envelopeFrom) {
		this.envelopeFrom = envelopeFrom;
	}

	public void setEnvelopeTo(InternetAddress[] envelopeTo) {
		this.envelopeTo = envelopeTo;
	}

	public void setFrom(InternetAddress from) {
		this.from = from;
	}

	public void setReplyTo(InternetAddress[] replyTo) {
		this.replyTo = replyTo;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public void setText(String text) {
		this.text = text;
	}

	public void setTo(InternetAddress[] to) {
		this.to = to;
	}

}
